<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue&三目运算符</title>
    <!-- 导入vue -->
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js"></script>
</head>
<style>
    .back {
        background-color: red;
    }
</style>
<body>
    <div id="app">
        <ul>
            <li v-for='(item,index) in arr'>
                <div :class=" index == indexVal ? 'back' : '' " @click='addBack(index)'>{{item.name}}{{index}}</div>
            </li>
        </ul>
    </div>
    <script>
        new Vue({
            el:'#app',
            data() {
                return {
                    arr:[{
                        id:1,
                        name:'html'
                    },{
                        id:2,
                        name:'css'
                    },{
                        id:3,
                        name:'js'
                    }],
                    indexVal:-1
                }
            },
            methods:{
                addBack(index) {
                    this.indexVal = index
                }
            }
        })
    </script>
</body>
</html>